

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/Mine.jpg">
  <link rel="icon" href="/img/Mine.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Chiam">
  <meta name="keywords" content="算法，安全">
  
    <meta name="description" content="『设计模式』状态模式（不起花里胡哨的名字了）23 种设计模式+额外常用设计模式汇总 (持续更新） 状态模式  允许一个对象在其内部状态改变时改变它的行为，这个对象看起来似乎修改了它的类。 状态模式主要解决的是当控制一个对象状态转换的条件表达式过于复杂时的情况。把状态的判断逻辑转移到表系不同状态的一系列类当中，可以把复杂的逻辑简化。 每个人、事务在不同的状态下会有不同表现动作，而一个状态又会在不同的">
<meta property="og:type" content="article">
<meta property="og:title" content="『设计模式』状态模式（不起花里胡哨的名字了）">
<meta property="og:url" content="http://example.com/2023/12/06/%E3%80%8E%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E3%80%8F%E7%8A%B6%E6%80%81%E6%A8%A1%E5%BC%8F%EF%BC%88%E4%B8%8D%E8%B5%B7%E8%8A%B1%E9%87%8C%E8%83%A1%E5%93%A8%E7%9A%84%E5%90%8D%E5%AD%97%E4%BA%86%EF%BC%89/index.html">
<meta property="og:site_name" content="Chiam 的个人主页">
<meta property="og:description" content="『设计模式』状态模式（不起花里胡哨的名字了）23 种设计模式+额外常用设计模式汇总 (持续更新） 状态模式  允许一个对象在其内部状态改变时改变它的行为，这个对象看起来似乎修改了它的类。 状态模式主要解决的是当控制一个对象状态转换的条件表达式过于复杂时的情况。把状态的判断逻辑转移到表系不同状态的一系列类当中，可以把复杂的逻辑简化。 每个人、事务在不同的状态下会有不同表现动作，而一个状态又会在不同的">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200510183005259.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzQ2MDIyNA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200616000818646.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="article:published_time" content="2023-12-05T16:11:45.189Z">
<meta property="article:modified_time" content="2023-12-05T16:20:21.380Z">
<meta property="article:author" content="Chiam">
<meta property="article:tag" content="算法，安全">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20200510183005259.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzQ2MDIyNA==,size_16,color_FFFFFF,t_70">
  
  
  
  <title>『设计模式』状态模式（不起花里胡哨的名字了） - Chiam 的个人主页</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="/css/custom.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":"❡"},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":2},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Chiam&#39;s Blogs</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="『设计模式』状态模式（不起花里胡哨的名字了）"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-12-06 00:11" pubdate>
          2023年12月6日 凌晨
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          6.3k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          53 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">『设计模式』状态模式（不起花里胡哨的名字了）</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="『设计模式』状态模式（不起花里胡哨的名字了）"><a href="#『设计模式』状态模式（不起花里胡哨的名字了）" class="headerlink" title="『设计模式』状态模式（不起花里胡哨的名字了）"></a>『设计模式』状态模式（不起花里胡哨的名字了）</h1><p><a target="_blank" rel="noopener" href="https://lunatic.blog.csdn.net/article/details/105578091">23 种设计模式+额外常用设计模式汇总 (持续更新）</a></p>
<h2><a name="t0" class="one-pan-link-mark"></a><a name="t0" class="one-pan-link-mark"></a><a id="_1" class="one-pan-link-mark"></a>状态模式</h2>
<ul>
<li>允许一个对象在其内部状态改变时改变它的行为，这个对象看起来似乎修改了它的类。</li>
<li>状态模式主要解决的是当控制一个对象状态转换的条件表达式过于复杂时的情况。把状态的判断逻辑转移到表系不同状态的一系列类当中，可以把复杂的逻辑简化。</li>
<li>每个人、事务在不同的状态下会有不同表现动作，而一个状态又会在不同的表现下转移到写一个不同的状态。</li>
<li>在State模式中我们将状态逻辑和动作实现进行分离。当一个操作中要维护大量的分支语句，并且这些分支依赖于对象的状态。State模式将每一个分支都封装到独立的类中。</li>
</ul>
<h2><a name="t1" class="one-pan-link-mark"></a><a name="t1" class="one-pan-link-mark"></a><a id="State_7" class="one-pan-link-mark"></a>State模式结构</h2>
<p><img src="https://img-blog.csdnimg.cn/20200510183005259.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzQ2MDIyNA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2><a name="t2" class="one-pan-link-mark"></a><a name="t2" class="one-pan-link-mark"></a><a id="_9" class="one-pan-link-mark"></a>优点</h2>
<ul>
<li>将与特定状态相关的行为局部化，并且将不同状态的行为分割开来。</li>
<li>消除庞大的条件分支语句，把各种状态转移逻辑分布到State的子类之间，减少了相互间的依赖。</li>
<li>显式化进行状态转换:为不同的状态引入独立的对象，使得状态的转换变得更如明确。而且状态对象可以保证上下文不会发生内部状态不一致的状况，因为上下文中只有一个变量来记录状态对象，只要为这一个变量赋值就可以了。</li>
</ul>
<h2><a name="t3" class="one-pan-link-mark"></a><a name="t3" class="one-pan-link-mark"></a><a id="_14" class="one-pan-link-mark"></a>缺点</h2>
<p>State模式问题主要是逻辑分散化，状态逻辑分布到了很多的State的子类中，很难看到整个的状态逻辑图，这也带来了代码的维护问题。</p>
<h2><a name="t4" class="one-pan-link-mark"></a><a name="t4" class="one-pan-link-mark"></a><a id="_16" class="one-pan-link-mark"></a>本质</h2>
<ul>
<li>根据状态来分离和选择行为</li>
<li>状态模式是状态驱动，由上下文负责。</li>
</ul>
<h2><a name="t5" class="one-pan-link-mark"></a><a name="t5" class="one-pan-link-mark"></a><a id="StateStrategy_19" class="one-pan-link-mark"></a>State模式和Strategy模式简单对比</h2>
<ul>
<li>State模式和Strategy模式有很大程度上的相似:它们都有-一个Context类，都是通过委托(组合)给一个具有多个派生类的多态基类实现Context的算法逻辑。</li>
<li>两者最大的差别就是State模式中派生类持有指向Context对象的引用，并通过这个引用调用Context中的方法，但在Strategy模式中就没有这种情况。</li>
</ul>

<h3 id="实现"><a href="#实现" class="headerlink" title="实现"></a>实现</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">State</span> &#123;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">Handle</span><span class="hljs-params">(Context context)</span>;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs java"> <span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">ConcreteStateA</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">State</span>&#123;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">Handle</span><span class="hljs-params">(Context context)</span> &#123;<br>        context.setState(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ConcreteStateB</span>()); <span class="hljs-comment">//设置A的下一个状态是B</span><br><br>    &#125;<br><br>&#125;<br><span class="hljs-keyword">class</span> <span class="hljs-title class_">ConcreteStateB</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">State</span>&#123;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">Handle</span><span class="hljs-params">(Context context)</span> &#123;<br>        context.setState(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ConcreteStateC</span>()); <span class="hljs-comment">//设置B的下一个状态是C</span><br>    &#125;<br><br>&#125;<br><span class="hljs-keyword">class</span> <span class="hljs-title class_">ConcreteStateC</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">State</span>&#123;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">Handle</span><span class="hljs-params">(Context context)</span> &#123;<br>        context.setState(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ConcreteStateA</span>()); <span class="hljs-comment">//设置C的下一个状态是A</span><br>    &#125;<br><br>&#125;<br><br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Context</span> &#123;<br>    State state;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-title function_">Context</span><span class="hljs-params">(State state)</span> &#123; <span class="hljs-comment">//定义Context的初始状态</span><br>        <span class="hljs-built_in">super</span>();<br>        <span class="hljs-built_in">this</span>.state = state;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> State <span class="hljs-title function_">getState</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> state;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setState</span><span class="hljs-params">(State state)</span> &#123;<br>        <span class="hljs-built_in">this</span>.state = state;<br>        System.out.println(<span class="hljs-string">&quot;当前状态为&quot;</span>+state);<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">request</span><span class="hljs-params">()</span>&#123;<br>        state.Handle(<span class="hljs-built_in">this</span>); <span class="hljs-comment">//对请求做处理并且指向下一个状态</span><br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<h2><a name="t6" class="one-pan-link-mark"></a><a name="t6" class="one-pan-link-mark"></a><a id="_22" class="one-pan-link-mark"></a>实例</h2>
<p>【问题】<br>
工作流中的请假流程：</p>
<ul>
<li>某人提出请假申请，先由项目经理审批，如果项目经理不同意，审批就直接结束。</li>
<li>如项目经理同意，再看是否超过3天，如果三天以内，审批直接结束。</li>
<li>否则，交给部门经理，部门络理审核后，无论是否同意，审批直接结束。</li>
</ul>
 
<p><img src="https://img-blog.csdnimg.cn/20200616000818646.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br></pre></td><td class="code"><pre><code class="hljs java"><br><br><span class="hljs-keyword">package</span> 状态模式;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Context</span> &#123;<br><br>    <span class="hljs-keyword">private</span> State st;<br><br>    <span class="hljs-keyword">private</span> <span class="hljs-type">int</span> days;<br><br>    <span class="hljs-keyword">private</span> String name;<br><br>    <span class="hljs-keyword">private</span> String pro;<br><br>    <span class="hljs-keyword">private</span> String dept;<br><br><br>    <span class="hljs-keyword">private</span> <span class="hljs-type">boolean</span> ProjectManager,DepartmentManager,BossManager;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-title function_">Context</span><span class="hljs-params">(<span class="hljs-type">int</span> days, String name, String pro, String dept, <span class="hljs-type">boolean</span> projectManager, <span class="hljs-type">boolean</span> departmentManager,</span><br><span class="hljs-params"></span><br><span class="hljs-params">    		<span class="hljs-type">boolean</span> boss)</span> &#123;<br><br>    	<span class="hljs-built_in">super</span>();<br><br>    	<span class="hljs-built_in">this</span>.days = days;<br><br>    	<span class="hljs-built_in">this</span>.name = name;<br><br>    	<span class="hljs-built_in">this</span>.pro = pro;<br><br>    	<span class="hljs-built_in">this</span>.dept = dept;<br><br>    	ProjectManager = projectManager;<br><br>    	DepartmentManager = departmentManager;<br><br>    	<span class="hljs-built_in">this</span>.BossManager = boss;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-type">boolean</span> <span class="hljs-title function_">isBossManager</span><span class="hljs-params">()</span> &#123;<br><br>    	<span class="hljs-keyword">return</span> BossManager;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setBossManager</span><span class="hljs-params">(<span class="hljs-type">boolean</span> bossManager)</span> &#123;<br><br>    	BossManager = bossManager;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-title function_">Context</span><span class="hljs-params">(  <span class="hljs-type">int</span> days, String name, String pro, String dept, <span class="hljs-type">boolean</span> projectManager,</span><br><span class="hljs-params"></span><br><span class="hljs-params">    		<span class="hljs-type">boolean</span> departmentManager)</span> &#123;<br><br>    	<span class="hljs-built_in">super</span>();<br><br><br><br>    	<span class="hljs-built_in">this</span>.days = days;<br><br>    	<span class="hljs-built_in">this</span>.name = name;<br><br>    	<span class="hljs-built_in">this</span>.pro = pro;<br><br>    	<span class="hljs-built_in">this</span>.dept = dept;<br><br>    	ProjectManager = projectManager;<br><br>    	DepartmentManager = departmentManager;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-title function_">Context</span><span class="hljs-params">()</span> &#123;<br><br>    	<span class="hljs-built_in">super</span>();<br><br>    	<span class="hljs-comment">// TODO Auto-generated constructor stub</span><br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-type">int</span> <span class="hljs-title function_">getDays</span><span class="hljs-params">()</span> &#123;<br><br>    	<span class="hljs-keyword">return</span> days;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setDays</span><span class="hljs-params">(<span class="hljs-type">int</span> days)</span> &#123;<br><br>    	<span class="hljs-built_in">this</span>.days = days;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getName</span><span class="hljs-params">()</span> &#123;<br><br>    	<span class="hljs-keyword">return</span> name;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setName</span><span class="hljs-params">(String name)</span> &#123;<br><br>    	<span class="hljs-built_in">this</span>.name = name;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-type">boolean</span> <span class="hljs-title function_">isProjectManager</span><span class="hljs-params">()</span> &#123;<br><br>    	<span class="hljs-keyword">return</span> ProjectManager;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setProjectManager</span><span class="hljs-params">(<span class="hljs-type">boolean</span> projectManager)</span> &#123;<br><br>    	ProjectManager = projectManager;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-type">boolean</span> <span class="hljs-title function_">isDepartmentManager</span><span class="hljs-params">()</span> &#123;<br><br>    	<span class="hljs-keyword">return</span> DepartmentManager;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getDept</span><span class="hljs-params">()</span> &#123;<br><br>    	<span class="hljs-keyword">return</span> dept;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setDept</span><span class="hljs-params">(String dept)</span> &#123;<br><br>    	<span class="hljs-built_in">this</span>.dept = dept;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getPro</span><span class="hljs-params">()</span> &#123;<br><br>    	<span class="hljs-keyword">return</span> pro;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setPro</span><span class="hljs-params">(String pro)</span> &#123;<br><br>    	<span class="hljs-built_in">this</span>.pro = pro;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setDepartmentManager</span><span class="hljs-params">(<span class="hljs-type">boolean</span> departmentManager)</span> &#123;<br><br>    	DepartmentManager = departmentManager;<br><br>    &#125;<br><br><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">leave</span><span class="hljs-params">()</span> &#123;<br><br>    	st.leave(<span class="hljs-built_in">this</span>);<br><br>    &#125;<br><br>&#125;<br><br><span class="hljs-keyword">package</span> 状态模式;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">State</span> &#123;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">leave</span><span class="hljs-params">(Context con)</span>;<br><br>&#125;<br><br><span class="hljs-keyword">package</span> 状态模式;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Accept</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">State</span> &#123;<br><br>    <span class="hljs-meta">@Override</span><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">leave</span><span class="hljs-params">(Context con)</span> &#123;<br><br>    	<span class="hljs-keyword">if</span>(con.isProjectManager()==<span class="hljs-literal">false</span>) &#123;<br><br>    		System.out.println(con.getPro()+<span class="hljs-string">&quot;经理不同意请假！&quot;</span>+con.getName()+<span class="hljs-string">&quot;的请假&quot;</span>);<br><br>    	&#125;<span class="hljs-keyword">else</span> &#123;<br><br>    		Less3 tdl=<span class="hljs-keyword">new</span> <span class="hljs-title class_">Less3</span>();<br><br>    		tdl.leave(con);<br><br>    	&#125;<br><br>    &#125;<br><br>&#125;<br><br><span class="hljs-keyword">package</span> 状态模式;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Less3</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">State</span> &#123;<br><br>    <span class="hljs-meta">@Override</span><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">leave</span><span class="hljs-params">(Context con)</span> &#123;<br><br>    	<span class="hljs-keyword">if</span>(con.getDays()&lt;=<span class="hljs-number">3</span>) &#123;<br><br>    		System.out.println(con.getPro() +<span class="hljs-string">&quot;项目经理同意！&quot;</span>+con.getName()+<span class="hljs-string">&quot;的请假审批通过！共请假&quot;</span>+con.getDays()+<span class="hljs-string">&quot;天！&quot;</span>);<br><br>    	&#125;<span class="hljs-keyword">else</span> &#123;<br><br>    		System.out.println(<span class="hljs-string">&quot;请假时间超过三天，请移至&quot;</span>+con.getDept()+<span class="hljs-string">&quot;部门经理处！&quot;</span>);<br><br>    		More3_Less7 tdo=<span class="hljs-keyword">new</span> <span class="hljs-title class_">More3_Less7</span>();<br><br>    		tdo.leave(con);<br><br>    	&#125;<br><br><br><br>    &#125;<br><br>&#125;<br><br><span class="hljs-keyword">package</span> 状态模式;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">More3_Less7</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">State</span> &#123;<br><br>    <span class="hljs-meta">@Override</span><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">leave</span><span class="hljs-params">(Context con)</span> &#123;<br><br>    	<span class="hljs-keyword">if</span>(con.getDays()&lt;=<span class="hljs-number">7</span>) &#123;<br><br>    		System.out.println(con.getDept()+<span class="hljs-string">&quot;部门经理同意！&quot;</span>+con.getName()+<span class="hljs-string">&quot;的请假审批通过！共请假&quot;</span>+con.getDays()+<span class="hljs-string">&quot;天！&quot;</span>);<br><br>    	&#125;<span class="hljs-keyword">else</span> &#123;<br><br>    		System.out.println(<span class="hljs-string">&quot;请假时间超过7天，请移至总经理！&quot;</span>);<br><br>    		More7 tdo=<span class="hljs-keyword">new</span> <span class="hljs-title class_">More7</span>();<br><br>    		tdo.leave(con);<br><br>    	&#125;<br><br><br><br>    &#125;<br><br>&#125;<br><br><span class="hljs-keyword">package</span> 状态模式;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">More7</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">State</span> &#123;<br><br>    <span class="hljs-meta">@Override</span><br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">leave</span><span class="hljs-params">(Context con)</span> &#123;<br><br>    	<span class="hljs-keyword">if</span>(con.isBossManager()==<span class="hljs-literal">true</span>) &#123;<br><br>    		System.out.println(con.getPro()+<span class="hljs-string">&quot;项目经理同意！&quot;</span>+con.getDept()+<span class="hljs-string">&quot;部门经理同意！总经理同意！&quot;</span>+con.getName()+<span class="hljs-string">&quot;的请假审批通过！共请假&quot;</span>+con.getDays()+<span class="hljs-string">&quot;天！&quot;</span>);<br><br>    	&#125;<span class="hljs-keyword">else</span> &#123;<br><br>    		System.out.println(con.getPro()+<span class="hljs-string">&quot;项目经理同意！&quot;</span>+con.getDept()+<span class="hljs-string">&quot;部门经理同意！总经理不同意！&quot;</span>+con.getName()+<span class="hljs-string">&quot;的请假审批不通过！&quot;</span>);<br><br>    	&#125;<br><br>    &#125;<br><br>&#125;<br><br><span class="hljs-keyword">package</span> 状态模式;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Client</span> &#123;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br><br>    	<span class="hljs-type">Context</span> <span class="hljs-variable">con</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Context</span>(<span class="hljs-number">8</span>,<span class="hljs-string">&quot;菜鸡&quot;</span>,<span class="hljs-string">&quot;设计模式&quot;</span>,<span class="hljs-string">&quot;设计&quot;</span>,<span class="hljs-literal">true</span>,<span class="hljs-literal">true</span>,<span class="hljs-literal">true</span>);<br><br>    	con.setName(<span class="hljs-string">&quot;菜鸡&quot;</span>);<br><br>    	con.setPro(<span class="hljs-string">&quot;设计模式&quot;</span>);<br><br>    	con.setDept(<span class="hljs-string">&quot;设计&quot;</span>);<br><br>    	con.setDays(<span class="hljs-number">8</span>);<br><br>    	con.setProjectManager(<span class="hljs-literal">true</span>);<br><br>    	con.setDepartmentManager(<span class="hljs-literal">true</span>);<br><br>    	con.leave();<br><br>    &#125;<br><br>&#125;<br><br></code></pre></td></tr></table></figure>

<pre><code class="hljs">
</code></pre>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" class="category-chain-item">设计模式</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>『设计模式』状态模式（不起花里胡哨的名字了）</div>
      <div>http://example.com/2023/12/06/『设计模式』状态模式（不起花里胡哨的名字了）/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Chiam</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年12月6日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/12/06/%E3%80%8E%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E3%80%8F%E7%91%9E%E5%B9%B8%E5%92%96%E5%95%A1%E8%BF%98%E6%98%AF%E6%98%9F%E5%B7%B4%E5%85%8B%EF%BC%8C%E4%B8%80%E6%9D%AF%E4%B8%8B%E5%8D%88%E8%8C%B6%E8%AE%A9%E6%88%91%E6%98%8E%E7%99%BD%20%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F-%E6%A8%A1%E6%9D%BF%E6%96%B9%E6%B3%95%E6%A8%A1%E5%BC%8F%EF%BC%88Template%20Method%20Pattern%EF%BC%89/" title="『设计模式』瑞幸咖啡还是星巴克，一杯下午茶让我明白 设计模式-模板方法模式（Template Method Pattern）">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">『设计模式』瑞幸咖啡还是星巴克，一杯下午茶让我明白 设计模式-模板方法模式（Template Method Pattern）</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/12/06/%E3%80%8E%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E3%80%8F%E6%92%A9%E5%A6%B9%E7%A7%98%E7%B1%8D%E7%AB%9F%E6%98%AF%E4%BD%BF%E7%94%A8%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E7%9A%84%E6%8A%BD%E8%B1%A1%E5%B7%A5%E5%8E%82%E6%A8%A1%E5%BC%8F/" title="『设计模式』撩妹秘籍竟是使用设计模式的抽象工厂模式">
                        <span class="hidden-mobile">『设计模式』撩妹秘籍竟是使用设计模式的抽象工厂模式</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"fIfc7WqUDZohlQuPc2lz5mJy-MdYXbMMI","appKey":"zjlAG3ZA3o4cBHVAkjzc2Z20","path":"window.location.pathname","placeholder":"留言仅限讨论，禁止广告等行为","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"https://fifc7wqu.api.lncldglobal.com","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <meta name="referrer" content="no-referrer" /> <footer id="footer" role="contentinfo"> <div class="divider"> <div class="wall"></div> <img class="animals" src="/img/footer_animals_new.png" srcset="/img/loading.gif" lazyload alt="Footer Animals"> </div> <div class="container" data-index="450"> <p> <a href="https://chiamzhang.github.io" target="_blank">DogEgg</a> <i class="iconfont icon-love"></i> <a href="#" target="_blank">LittePig</a> </p> <p> Powered by  <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-pen"></i> Theme  <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> </p> </div> </footer> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>




  
<script src="/js/love.js"></script>
<script src="/js/funnyTitle.js"></script>
<script src="/js/backTop.js"></script>
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiaoxuehua.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/wanko.model.json"},"display":{"position":"left","width":150,"height":150,"hOffset":20,"vOffset":0},"mobile":{"show":false,"scale":0.5},"react":{"opacity":0.9},"log":false});</script></body>
</html>
